package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OaCostExpenseLists;
import com.ruoyi.system.service.IOaCostExpenseListsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成本费用清单Controller
 *
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/lists")
@Transactional
public class OaCostExpenseListsController extends BaseController
{
    @Autowired
    private IOaCostExpenseListsService oaCostExpenseListsService;

    /**
     * 查询成本费用清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:lists:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaCostExpenseLists oaCostExpenseLists)
    {
        startPage();
        List<OaCostExpenseLists> list = oaCostExpenseListsService.selectOaCostExpenseListsList(oaCostExpenseLists);
        return getDataTable(list);
    }

    /**
     * 导出成本费用清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:lists:export')")
    @Log(title = "成本费用清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaCostExpenseLists oaCostExpenseLists)
    {
        List<OaCostExpenseLists> list = oaCostExpenseListsService.selectOaCostExpenseListsList(oaCostExpenseLists);
        ExcelUtil<OaCostExpenseLists> util = new ExcelUtil<OaCostExpenseLists>(OaCostExpenseLists.class);
        util.exportExcel(response, list, "成本费用清单数据");
    }

    /**
     * 获取成本费用清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:lists:query')")
    @GetMapping(value = "/{expenseId}")
    public AjaxResult getInfo(@PathVariable("expenseId") Long expenseId)
    {
        return success(oaCostExpenseListsService.selectOaCostExpenseListsByExpenseId(expenseId));
    }

    /**
     * 新增成本费用清单
     */
    @PreAuthorize("@ss.hasPermi('system:lists:add')")
    @Log(title = "成本费用清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaCostExpenseLists oaCostExpenseLists)
    {
        return toAjax(oaCostExpenseListsService.insertOaCostExpenseLists(oaCostExpenseLists));
    }

    /**
     * 修改成本费用清单
     */
    @PreAuthorize("@ss.hasPermi('system:lists:edit')")
    @Log(title = "成本费用清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaCostExpenseLists oaCostExpenseLists)
    {
        return toAjax(oaCostExpenseListsService.updateOaCostExpenseLists(oaCostExpenseLists));
    }

    /**
     * 删除成本费用清单
     */
    @PreAuthorize("@ss.hasPermi('system:lists:remove')")
    @Log(title = "成本费用清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expenseIds}")
    public AjaxResult remove(@PathVariable Long[] expenseIds)
    {
        return toAjax(oaCostExpenseListsService.deleteOaCostExpenseListsByExpenseIds(expenseIds));
    }
}
